<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class StringIO - stringio: Ruby Standard Library Documentation</title>


<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>

<script src="./js/jquery-3.2.0.min.js"></script>

<script src="./js/vue.min.js"></script>
<script src="./js/js.cookie.min.js"></script>

<link href="./css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="./css/rdoc.css" rel="stylesheet">
<link href="./css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
  var index_rel_prefix = "./";
  var darkModeCsseHref = "./css/rdoc-dm.css"
  var defaultModeCssHref = "./css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="./index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    

    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link">Object
</div>

        
<div id="includes-section" class="nav-section">
  <h3>Included Modules</h3>

  <ul class="link-list">
    <li><span class="include">Enumerable</span>
    <li><a class="include" href="IO/generic_readable.html">IO::generic_readable</a>
    <li><a class="include" href="IO/generic_writable.html">IO::generic_writable</a>
  </ul>
</div>

        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-new">::new</a>
    <li ><a href="#method-c-open">::open</a>
    <li ><a href="#method-i-binmode">#binmode</a>
    <li ><a href="#method-i-close">#close</a>
    <li ><a href="#method-i-close_read">#close_read</a>
    <li ><a href="#method-i-close_write">#close_write</a>
    <li ><a href="#method-i-closed-3F">#closed?</a>
    <li ><a href="#method-i-closed_read-3F">#closed_read?</a>
    <li ><a href="#method-i-closed_write-3F">#closed_write?</a>
    <li ><a href="#method-i-each">#each</a>
    <li ><a href="#method-i-each_byte">#each_byte</a>
    <li ><a href="#method-i-each_char">#each_char</a>
    <li ><a href="#method-i-each_codepoint">#each_codepoint</a>
    <li ><a href="#method-i-each_line">#each_line</a>
    <li ><a href="#method-i-eof">#eof</a>
    <li ><a href="#method-i-eof-3F">#eof?</a>
    <li ><a href="#method-i-external_encoding">#external_encoding</a>
    <li ><a href="#method-i-fcntl">#fcntl</a>
    <li ><a href="#method-i-fileno">#fileno</a>
    <li ><a href="#method-i-flush">#flush</a>
    <li ><a href="#method-i-fsync">#fsync</a>
    <li ><a href="#method-i-getbyte">#getbyte</a>
    <li ><a href="#method-i-getc">#getc</a>
    <li ><a href="#method-i-gets">#gets</a>
    <li ><a href="#method-i-internal_encoding">#internal_encoding</a>
    <li ><a href="#method-i-isatty">#isatty</a>
    <li ><a href="#method-i-length">#length</a>
    <li ><a href="#method-i-lineno">#lineno</a>
    <li ><a href="#method-i-lineno-3D">#lineno=</a>
    <li ><a href="#method-i-pid">#pid</a>
    <li ><a href="#method-i-pos">#pos</a>
    <li ><a href="#method-i-pos-3D">#pos=</a>
    <li ><a href="#method-i-pread">#pread</a>
    <li ><a href="#method-i-putc">#putc</a>
    <li ><a href="#method-i-read">#read</a>
    <li ><a href="#method-i-readlines">#readlines</a>
    <li ><a href="#method-i-reopen">#reopen</a>
    <li ><a href="#method-i-rewind">#rewind</a>
    <li ><a href="#method-i-seek">#seek</a>
    <li ><a href="#method-i-set_encoding">#set_encoding</a>
    <li ><a href="#method-i-set_encoding_by_bom">#set_encoding_by_bom</a>
    <li ><a href="#method-i-size">#size</a>
    <li ><a href="#method-i-string">#string</a>
    <li ><a href="#method-i-string-3D">#string=</a>
    <li ><a href="#method-i-sync">#sync</a>
    <li ><a href="#method-i-sync-3D">#sync=</a>
    <li ><a href="#method-i-tell">#tell</a>
    <li ><a href="#method-i-truncate">#truncate</a>
    <li ><a href="#method-i-tty-3F">#tty?</a>
    <li ><a href="#method-i-ungetbyte">#ungetbyte</a>
    <li ><a href="#method-i-ungetc">#ungetc</a>
    <li ><a href="#method-i-write">#write</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-StringIO">
    <h1 id="class-StringIO" class="class">
      class StringIO
    </h1>

    <section class="description">
    
<p>IO streams for strings, with access similar to <a href="IO.html"><code>IO</code></a>; see <a href="IO.html"><code>IO</code></a>.</p>

<h3 id="class-StringIO-label-About+the+Examples">About the Examples<span><a href="#class-StringIO-label-About+the+Examples">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>Examples on this page assume that StringIO has been required:</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;stringio&#39;</span>
</pre>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">


      <section class="constants-list">
      <header>
      <h3>Constants</h3>
      </header>
      <dl>
          <dt id="VERSION">VERSION
          <dd>
        </dl>
        </section>



                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-new" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          new(string = &#39;&#39;, mode = &#39;r+&#39;) &rarr; new_stringio
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Note that <code>mode</code> defaults to <code>&#39;r&#39;</code> if <code>string</code> is frozen.</p>

<p>Returns a new StringIO instance formed from <code>string</code> and <code>mode</code>; see Access Modes:</p>

<pre class="ruby"><span class="ruby-identifier">strio</span> = <span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">new</span> <span class="ruby-comment"># =&gt; #&lt;StringIO&gt;</span>
<span class="ruby-identifier">strio</span>.<span class="ruby-identifier">close</span>
</pre>

<p>The instance should be closed when no longer needed.</p>

<p>Related: <a href="StringIO.html#method-c-open"><code>StringIO.open</code></a> (accepts block; closes automatically).</p>

                              <div class="method-source-code" id="new-source">
            <pre>static VALUE
strio_initialize(int argc, VALUE *argv, VALUE self)
{
    struct StringIO *ptr = check_strio(self);

    if (!ptr) {
        DATA_PTR(self) = ptr = strio_alloc();
    }
    rb_call_super(0, 0);
    return strio_init(argc, argv, ptr, self);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-open" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          open(string = &#39;&#39;, mode = &#39;r+&#39;) {|strio| ... }
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Note that <code>mode</code> defaults to <code>&#39;r&#39;</code> if <code>string</code> is frozen.</p>

<p>Creates a new StringIO instance formed from <code>string</code> and <code>mode</code>; see Access Modes.</p>

<p>With no block, returns the new instance:</p>

<pre class="ruby"><span class="ruby-identifier">strio</span> = <span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">open</span> <span class="ruby-comment"># =&gt; #&lt;StringIO&gt;</span>
</pre>

<p>With a block, calls the block with the new instance and returns the block’s value; closes the instance on block exit.</p>

<pre class="ruby"><span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">open</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">strio</span><span class="ruby-operator">|</span> <span class="ruby-identifier">p</span> <span class="ruby-identifier">strio</span> }
<span class="ruby-comment"># =&gt; #&lt;StringIO&gt;</span>
</pre>

<p>Related: <a href="StringIO.html#method-c-new"><code>StringIO.new</code></a>.</p>

                              <div class="method-source-code" id="open-source">
            <pre>static VALUE
strio_s_open(int argc, VALUE *argv, VALUE klass)
{
    VALUE obj = rb_class_new_instance_kw(argc, argv, klass, RB_PASS_CALLED_KEYWORDS);
    if (!rb_block_given_p()) return obj;
    return rb_ensure(rb_yield, obj, strio_finalize, obj);
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-binmode" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          binmode &rarr; self
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sets the data mode in <code>self</code> to binary mode; see Data Mode.</p>

                              <div class="method-source-code" id="binmode-source">
            <pre>static VALUE
strio_binmode(VALUE self)
{
    struct StringIO *ptr = StringIO(self);
    rb_encoding *enc = rb_ascii8bit_encoding();

    ptr-&gt;enc = enc;
    if (WRITABLE(self)) {
        rb_enc_associate(ptr-&gt;string, enc);
    }
    return self;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-close" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          close &rarr; nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Closes <code>self</code> for both reading and writing.</p>

<p>Raises IOError if reading or writing is attempted.</p>

<p>Related: <a href="StringIO.html#method-i-close_read"><code>StringIO#close_read</code></a>, <a href="StringIO.html#method-i-close_write"><code>StringIO#close_write</code></a>.</p>

                              <div class="method-source-code" id="close-source">
            <pre>static VALUE
strio_close(VALUE self)
{
    StringIO(self);
    RBASIC(self)-&gt;flags &amp;= ~STRIO_READWRITE;
    return Qnil;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-close_read" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          close_read &rarr; nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Closes <code>self</code> for reading; closed-write setting remains unchanged.</p>

<p>Raises IOError if reading is attempted.</p>

<p>Related: <a href="StringIO.html#method-i-close"><code>StringIO#close</code></a>, <a href="StringIO.html#method-i-close_write"><code>StringIO#close_write</code></a>.</p>

                              <div class="method-source-code" id="close_read-source">
            <pre>static VALUE
strio_close_read(VALUE self)
{
    struct StringIO *ptr = StringIO(self);
    if (!(ptr-&gt;flags &amp; FMODE_READABLE)) {
        rb_raise(rb_eIOError, &quot;closing non-duplex IO for reading&quot;);
    }
    RBASIC(self)-&gt;flags &amp;= ~STRIO_READABLE;
    return Qnil;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-close_write" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          close_write &rarr; nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Closes <code>self</code> for writing; closed-read setting remains unchanged.</p>

<p>Raises IOError if writing is attempted.</p>

<p>Related: <a href="StringIO.html#method-i-close"><code>StringIO#close</code></a>, <a href="StringIO.html#method-i-close_read"><code>StringIO#close_read</code></a>.</p>

                              <div class="method-source-code" id="close_write-source">
            <pre>static VALUE
strio_close_write(VALUE self)
{
    struct StringIO *ptr = StringIO(self);
    if (!(ptr-&gt;flags &amp; FMODE_WRITABLE)) {
        rb_raise(rb_eIOError, &quot;closing non-duplex IO for writing&quot;);
    }
    RBASIC(self)-&gt;flags &amp;= ~STRIO_WRITABLE;
    return Qnil;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-closed-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          closed? &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if <code>self</code> is closed for both reading and writing, <code>false</code> otherwise.</p>

                              <div class="method-source-code" id="closed-3F-source">
            <pre>static VALUE
strio_closed(VALUE self)
{
    StringIO(self);
    if (!CLOSED(self)) return Qfalse;
    return Qtrue;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-closed_read-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          closed_read? &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if <code>self</code> is closed for reading, <code>false</code> otherwise.</p>

                              <div class="method-source-code" id="closed_read-3F-source">
            <pre>static VALUE
strio_closed_read(VALUE self)
{
    StringIO(self);
    if (READABLE(self)) return Qfalse;
    return Qtrue;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-closed_write-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          closed_write? &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if <code>self</code> is closed for writing, <code>false</code> otherwise.</p>

                              <div class="method-source-code" id="closed_write-3F-source">
            <pre>static VALUE
strio_closed_write(VALUE self)
{
    StringIO(self);
    if (WRITABLE(self)) return Qfalse;
    return Qtrue;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-each" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">each</span><span
                                class="method-args">(sep, limit, chomp: false) {|line| } -&gt; self</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Calls the block with each remaining line read from the stream; does nothing if already at end-of-file; returns <code>self</code>. See <a href="IO.html#class-IO-label-Line+IO">Line IO</a>.</p>

                              <div class="method-source-code" id="each-source">
            <pre>static VALUE
strio_each(int argc, VALUE *argv, VALUE self)
{
    VALUE line;
    struct getline_arg arg;

    StringIO(self);
    RETURN_ENUMERATOR(self, argc, argv);

    if (prepare_getline_args(&amp;arg, argc, argv)-&gt;limit == 0) {
        rb_raise(rb_eArgError, &quot;invalid limit: 0 for each_line&quot;);
    }

    while (!NIL_P(line = strio_getline(&amp;arg, readable(self)))) {
        rb_yield(line);
    }
    return self;
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="StringIO.html#method-i-each_line">each_line</a>
                            </div>

                          </div>

                  <div id="method-i-each_byte" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          each_byte {|byte| ... } &rarr; self
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>With a block given, calls the block with each remaining byte in the stream; see <a href="IO.html#class-IO-label-Byte+IO">Byte IO</a>.</p>

<p>With no block given, returns an enumerator.</p>

                              <div class="method-source-code" id="each_byte-source">
            <pre>static VALUE
strio_each_byte(VALUE self)
{
    struct StringIO *ptr;

    RETURN_ENUMERATOR(self, 0, 0);

    while ((ptr = strio_to_read(self)) != NULL) {
        char c = RSTRING_PTR(ptr-&gt;string)[ptr-&gt;pos++];
        rb_yield(CHR2FIX(c));
    }
    return self;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-each_char" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          each_char {|c| ... } &rarr; self
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>With a block given, calls the block with each remaining character in the stream; see <a href="IO.html#class-IO-label-Character+IO">Character IO</a>.</p>

<p>With no block given, returns an enumerator.</p>

                              <div class="method-source-code" id="each_char-source">
            <pre>static VALUE
strio_each_char(VALUE self)
{
    VALUE c;

    RETURN_ENUMERATOR(self, 0, 0);

    while (!NIL_P(c = strio_getc(self))) {
        rb_yield(c);
    }
    return self;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-each_codepoint" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          each_codepoint {|codepoint| ... } &rarr; self
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>With a block given, calls the block with each remaining codepoint in the stream; see <a href="IO.html#class-IO-label-Codepoint+IO">Codepoint IO</a>.</p>

<p>With no block given, returns an enumerator.</p>

                              <div class="method-source-code" id="each_codepoint-source">
            <pre>static VALUE
strio_each_codepoint(VALUE self)
{
    struct StringIO *ptr;
    rb_encoding *enc;
    unsigned int c;
    int n;

    RETURN_ENUMERATOR(self, 0, 0);

    ptr = readable(self);
    enc = get_enc(ptr);
    while ((ptr = strio_to_read(self)) != NULL) {
        c = rb_enc_codepoint_len(RSTRING_PTR(ptr-&gt;string)+ptr-&gt;pos,
                                 RSTRING_END(ptr-&gt;string), &amp;n, enc);
        ptr-&gt;pos += n;
        rb_yield(UINT2NUM(c));
    }
    return self;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-each_line" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">each_line</span><span
                                class="method-args">(*args)</span>
                            </div>

                            <div class="method-description">
                              <p>Calls the block with each remaining line read from the stream; does nothing if already at end-of-file; returns <code>self</code>. See <a href="IO.html#class-IO-label-Line+IO">Line IO</a>.</p>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="StringIO.html#method-i-each">each</a>
                            </div>
                          </div>

                  <div id="method-i-eof" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">eof</span><span
                                class="method-args"> -&gt; true or false</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if positioned at end-of-stream, <code>false</code> otherwise; see Position.</p>

<p>Raises IOError if the stream is not opened for reading.</p>

                              <div class="method-source-code" id="eof-source">
            <pre>static VALUE
strio_eof(VALUE self)
{
    if (strio_to_read(self)) return Qfalse;
    return Qtrue;
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="StringIO.html#method-i-eof-3F">eof?</a>
                            </div>

                          </div>

                  <div id="method-i-eof-3F" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">eof?</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if positioned at end-of-stream, <code>false</code> otherwise; see Position.</p>

<p>Raises IOError if the stream is not opened for reading.</p>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="StringIO.html#method-i-eof">eof</a>
                            </div>
                          </div>

                  <div id="method-i-external_encoding" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          external_encoding   &rarr; encoding
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the Encoding object that represents the encoding of the file. If the stream is write mode and no encoding is specified, returns <code>nil</code>.</p>

                              <div class="method-source-code" id="external_encoding-source">
            <pre>static VALUE
strio_external_encoding(VALUE self)
{
    struct StringIO *ptr = StringIO(self);
    return rb_enc_from_encoding(get_enc(ptr));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-fcntl" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">fcntl</span><span
                                class="method-args">(*args)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Raises NotImplementedError.</p>

                              <div class="method-source-code" id="fcntl-source">
            <pre>static VALUE
strio_unimpl(int argc, VALUE *argv, VALUE self)
{
    StringIO(self);
    rb_notimplement();

    UNREACHABLE;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-fileno" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">fileno</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>nil</code>.  Just for compatibility to <a href="IO.html"><code>IO</code></a>.</p>

                              <div class="method-source-code" id="fileno-source">
            <pre>static VALUE
strio_nil(VALUE self)
{
    StringIO(self);
    return Qnil;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-flush" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">flush</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns an object itself.  Just for compatibility to <a href="IO.html"><code>IO</code></a>.</p>

                              <div class="method-source-code" id="flush-source">
            <pre>static VALUE
strio_self(VALUE self)
{
    StringIO(self);
    return self;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-fsync" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">fsync</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns 0.  Just for compatibility to <a href="IO.html"><code>IO</code></a>.</p>

                              <div class="method-source-code" id="fsync-source">
            <pre>static VALUE
strio_0(VALUE self)
{
    StringIO(self);
    return INT2FIX(0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-getbyte" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          getbyte &rarr; byte or nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Reads and returns the next 8-bit byte from the stream; see <a href="IO.html#class-IO-label-Byte+IO">Byte IO</a>.</p>

                              <div class="method-source-code" id="getbyte-source">
            <pre>static VALUE
strio_getbyte(VALUE self)
{
    struct StringIO *ptr = readable(self);
    int c;
    if (ptr-&gt;pos &gt;= RSTRING_LEN(ptr-&gt;string)) {
        return Qnil;
    }
    c = RSTRING_PTR(ptr-&gt;string)[ptr-&gt;pos++];
    return CHR2FIX(c);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-getc" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          getc &rarr; character or nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Reads and returns the next character from the stream; see <a href="IO.html#class-IO-label-Character+IO">Character IO</a>.</p>

                              <div class="method-source-code" id="getc-source">
            <pre>static VALUE
strio_getc(VALUE self)
{
    struct StringIO *ptr = readable(self);
    rb_encoding *enc = get_enc(ptr);
    VALUE str = ptr-&gt;string;
    long pos = ptr-&gt;pos;
    int len;
    char *p;

    if (pos &gt;= RSTRING_LEN(str)) {
        return Qnil;
    }
    p = RSTRING_PTR(str)+pos;
    len = rb_enc_mbclen(p, RSTRING_END(str), enc);
    ptr-&gt;pos += len;
    return enc_subseq(str, pos, len, enc);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-gets" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          gets(sep = $/, chomp: false) &rarr; string or nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          gets(limit, chomp: false) &rarr; string or nil
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          gets(sep, limit, chomp: false) &rarr; string or nil
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Reads and returns a line from the stream; assigns the return value to <code>$_</code>; see <a href="IO.html#class-IO-label-Line+IO">Line IO</a>.</p>

                              <div class="method-source-code" id="gets-source">
            <pre>static VALUE
strio_gets(int argc, VALUE *argv, VALUE self)
{
    struct getline_arg arg;
    VALUE str;

    if (prepare_getline_args(&amp;arg, argc, argv)-&gt;limit == 0) {
        struct StringIO *ptr = readable(self);
        return rb_enc_str_new(0, 0, get_enc(ptr));
    }

    str = strio_getline(&amp;arg, readable(self));
    rb_lastline_set(str);
    return str;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-internal_encoding" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          internal_encoding   &rarr; encoding
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the Encoding of the internal string if conversion is specified.  Otherwise returns <code>nil</code>.</p>

                              <div class="method-source-code" id="internal_encoding-source">
            <pre>static VALUE
strio_internal_encoding(VALUE self)
{
    return Qnil;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-isatty" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">isatty</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>false</code>.  Just for compatibility to <a href="IO.html"><code>IO</code></a>.</p>

                              <div class="method-source-code" id="isatty-source">
            <pre>static VALUE
strio_false(VALUE self)
{
    StringIO(self);
    return Qfalse;
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="StringIO.html#method-i-tty-3F">tty?</a>
                            </div>

                          </div>

                  <div id="method-i-length" class="method-detail method-alias">
                      <div class="method-heading">
                        <span class="method-callseq">
                          length &rarr; integer
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns the size of the buffer string.</p>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="StringIO.html#method-i-size">size</a>
                            </div>
                          </div>

                  <div id="method-i-lineno" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          lineno &rarr; current_line_number
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the current line number in <code>self</code>; see <a href="IO.html#class-IO-label-Line+Number">Line Number</a>.</p>

                              <div class="method-source-code" id="lineno-source">
            <pre>static VALUE
strio_get_lineno(VALUE self)
{
    return LONG2NUM(StringIO(self)-&gt;lineno);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-lineno-3D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          lineno = new_line_number &rarr; new_line_number
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sets the current line number in <code>self</code> to the given <code>new_line_number</code>; see <a href="IO.html#class-IO-label-Line+Number">Line Number</a>.</p>

                              <div class="method-source-code" id="lineno-3D-source">
            <pre>static VALUE
strio_set_lineno(VALUE self, VALUE lineno)
{
    StringIO(self)-&gt;lineno = NUM2LONG(lineno);
    return lineno;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-pid" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">pid</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>nil</code>.  Just for compatibility to <a href="IO.html"><code>IO</code></a>.</p>

                              <div class="method-source-code" id="pid-source">
            <pre>static VALUE
strio_nil(VALUE self)
{
    StringIO(self);
    return Qnil;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-pos" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          pos &rarr; stream_position
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the current position (in bytes); see <a href="IO.html#class-IO-label-Position">Position</a>.</p>

                              <div class="method-source-code" id="pos-source">
            <pre>static VALUE
strio_get_pos(VALUE self)
{
    return LONG2NUM(StringIO(self)-&gt;pos);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-pos-3D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          pos = new_position &rarr; new_position
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sets the current position (in bytes); see <a href="IO.html#class-IO-label-Position">Position</a>.</p>

                              <div class="method-source-code" id="pos-3D-source">
            <pre>static VALUE
strio_set_pos(VALUE self, VALUE pos)
{
    struct StringIO *ptr = StringIO(self);
    long p = NUM2LONG(pos);
    if (p &lt; 0) {
        error_inval(0);
    }
    ptr-&gt;pos = p;
    return pos;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-pread" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          pread(maxlen, offset)             &rarr; string
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          pread(maxlen, offset, out_string) &rarr; string
                              </span>
                            </div>

                            <div class="method-description">
                              <p>See IO#pread.</p>

                              <div class="method-source-code" id="pread-source">
            <pre>static VALUE
strio_pread(int argc, VALUE *argv, VALUE self)
{
    VALUE rb_len, rb_offset, rb_buf;
    rb_scan_args(argc, argv, &quot;21&quot;, &amp;rb_len, &amp;rb_offset, &amp;rb_buf);
    long len = NUM2LONG(rb_len);
    long offset = NUM2LONG(rb_offset);

    if (len &lt; 0) {
        rb_raise(rb_eArgError, &quot;negative string size (or size too big): %&quot; PRIsVALUE, rb_len);
    }

    if (offset &lt; 0) {
        rb_syserr_fail_str(EINVAL, rb_sprintf(&quot;pread: Invalid offset argument: %&quot; PRIsVALUE, rb_offset));
    }

    struct StringIO *ptr = readable(self);

    if (offset &gt;= RSTRING_LEN(ptr-&gt;string)) {
        rb_eof_error();
    }

    if (NIL_P(rb_buf)) {
        return strio_substr(ptr, offset, len, rb_ascii8bit_encoding());
    }

    long rest = RSTRING_LEN(ptr-&gt;string) - offset;
    if (len &gt; rest) len = rest;
    rb_str_resize(rb_buf, len);
    rb_enc_associate(rb_buf, rb_ascii8bit_encoding());
    MEMCPY(RSTRING_PTR(rb_buf), RSTRING_PTR(ptr-&gt;string) + offset, char, len);
    return rb_buf;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-putc" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          putc(obj)    &rarr; obj
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>See IO#putc.</p>

                              <div class="method-source-code" id="putc-source">
            <pre>static VALUE
strio_putc(VALUE self, VALUE ch)
{
    struct StringIO *ptr = writable(self);
    VALUE str;

    check_modifiable(ptr);
    if (RB_TYPE_P(ch, T_STRING)) {
        str = rb_str_substr(ch, 0, 1);
    }
    else {
        char c = NUM2CHR(ch);
        str = rb_str_new(&amp;c, 1);
    }
    strio_write(self, str);
    return ch;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-read" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          read([length [, outbuf]])    &rarr; string, outbuf, or nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>See IO#read.</p>

                              <div class="method-source-code" id="read-source">
            <pre>static VALUE
strio_read(int argc, VALUE *argv, VALUE self)
{
    struct StringIO *ptr = readable(self);
    VALUE str = Qnil;
    long len;
    int binary = 0;

    switch (argc) {
      case 2:
        str = argv[1];
        if (!NIL_P(str)) {
            StringValue(str);
            rb_str_modify(str);
        }
        /* fall through */
      case 1:
        if (!NIL_P(argv[0])) {
            len = NUM2LONG(argv[0]);
            if (len &lt; 0) {
                rb_raise(rb_eArgError, &quot;negative length %ld given&quot;, len);
            }
            if (len &gt; 0 &amp;&amp; ptr-&gt;pos &gt;= RSTRING_LEN(ptr-&gt;string)) {
                if (!NIL_P(str)) rb_str_resize(str, 0);
                return Qnil;
            }
            binary = 1;
            break;
        }
        /* fall through */
      case 0:
        len = RSTRING_LEN(ptr-&gt;string);
        if (len &lt;= ptr-&gt;pos) {
            rb_encoding *enc = get_enc(ptr);
            if (NIL_P(str)) {
                str = rb_str_new(0, 0);
            }
            else {
                rb_str_resize(str, 0);
            }
            rb_enc_associate(str, enc);
            return str;
        }
        else {
            len -= ptr-&gt;pos;
        }
        break;
      default:
        rb_error_arity(argc, 0, 2);
    }
    if (NIL_P(str)) {
        rb_encoding *enc = binary ? rb_ascii8bit_encoding() : get_enc(ptr);
        str = strio_substr(ptr, ptr-&gt;pos, len, enc);
    }
    else {
        long rest = RSTRING_LEN(ptr-&gt;string) - ptr-&gt;pos;
        if (len &gt; rest) len = rest;
        rb_str_resize(str, len);
        MEMCPY(RSTRING_PTR(str), RSTRING_PTR(ptr-&gt;string) + ptr-&gt;pos, char, len);
        if (binary)
            rb_enc_associate(str, rb_ascii8bit_encoding());
        else
            rb_enc_copy(str, ptr-&gt;string);
    }
    ptr-&gt;pos += RSTRING_LEN(str);
    return str;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-readlines" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          readlines(sep=$/, chomp: false)     &rarr;   array
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          readlines(limit, chomp: false)      &rarr;   array
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          readlines(sep, limit, chomp: false) &rarr;   array
                              </span>
                            </div>

                            <div class="method-description">
                              <p>See IO#readlines.</p>

                              <div class="method-source-code" id="readlines-source">
            <pre>static VALUE
strio_readlines(int argc, VALUE *argv, VALUE self)
{
    VALUE ary, line;
    struct getline_arg arg;

    StringIO(self);
    ary = rb_ary_new();
    if (prepare_getline_args(&amp;arg, argc, argv)-&gt;limit == 0) {
        rb_raise(rb_eArgError, &quot;invalid limit: 0 for readlines&quot;);
    }

    while (!NIL_P(line = strio_getline(&amp;arg, readable(self)))) {
        rb_ary_push(ary, line);
    }
    return ary;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-reopen" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          reopen(other, mode = &#39;r+&#39;) &rarr; self
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Reinitializes the stream with the given <code>other</code> (string or <a href="StringIO.html"><code>StringIO</code></a>) and <code>mode</code>; see IO.new:</p>

<pre class="ruby"><span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">open</span>(<span class="ruby-string">&#39;foo&#39;</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">strio</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">strio</span>.<span class="ruby-identifier">string</span>
  <span class="ruby-identifier">strio</span>.<span class="ruby-identifier">reopen</span>(<span class="ruby-string">&#39;bar&#39;</span>)
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">strio</span>.<span class="ruby-identifier">string</span>
  <span class="ruby-identifier">other_strio</span> = <span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;baz&#39;</span>)
  <span class="ruby-identifier">strio</span>.<span class="ruby-identifier">reopen</span>(<span class="ruby-identifier">other_strio</span>)
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">strio</span>.<span class="ruby-identifier">string</span>
  <span class="ruby-identifier">other_strio</span>.<span class="ruby-identifier">close</span>
<span class="ruby-keyword">end</span>
</pre>

<p>Output:</p>

<pre class="ruby"><span class="ruby-string">&quot;foo&quot;</span>
<span class="ruby-string">&quot;bar&quot;</span>
<span class="ruby-string">&quot;baz&quot;</span>
</pre>

                              <div class="method-source-code" id="reopen-source">
            <pre>static VALUE
strio_reopen(int argc, VALUE *argv, VALUE self)
{
    rb_io_taint_check(self);
    if (argc == 1 &amp;&amp; !RB_TYPE_P(*argv, T_STRING)) {
        return strio_copy(self, *argv);
    }
    return strio_init(argc, argv, StringIO(self), self);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-rewind" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          rewind &rarr; 0
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sets the current position and line number to zero; see <a href="IO.html#class-IO-label-Position">Position</a> and <a href="IO.html#class-IO-label-Line+Number">Line Number</a>.</p>

                              <div class="method-source-code" id="rewind-source">
            <pre>static VALUE
strio_rewind(VALUE self)
{
    struct StringIO *ptr = StringIO(self);
    ptr-&gt;pos = 0;
    ptr-&gt;lineno = 0;
    return INT2FIX(0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-seek" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          seek(offset, whence = SEEK_SET) &rarr; 0
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sets the current position to the given integer <code>offset</code> (in bytes), with respect to a given constant <code>whence</code>; see <a href="IO.html#class-IO-label-Position">Position</a>.</p>

                              <div class="method-source-code" id="seek-source">
            <pre>static VALUE
strio_seek(int argc, VALUE *argv, VALUE self)
{
    VALUE whence;
    struct StringIO *ptr = StringIO(self);
    long amount, offset;

    rb_scan_args(argc, argv, &quot;11&quot;, NULL, &amp;whence);
    amount = NUM2LONG(argv[0]);
    if (CLOSED(self)) {
        rb_raise(rb_eIOError, &quot;closed stream&quot;);
    }
    switch (NIL_P(whence) ? 0 : NUM2LONG(whence)) {
      case 0:
        offset = 0;
        break;
      case 1:
        offset = ptr-&gt;pos;
        break;
      case 2:
        offset = RSTRING_LEN(ptr-&gt;string);
        break;
      default:
        error_inval(&quot;invalid whence&quot;);
    }
    if (amount &gt; LONG_MAX - offset || amount + offset &lt; 0) {
        error_inval(0);
    }
    ptr-&gt;pos = amount + offset;
    return INT2FIX(0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-set_encoding" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          set_encoding(ext_enc, [int_enc[, opt]])  &rarr; strio
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Specify the encoding of the <a href="StringIO.html"><code>StringIO</code></a> as <em>ext_enc</em>. Use the default external encoding if <em>ext_enc</em> is nil. 2nd argument <em>int_enc</em> and optional hash <em>opt</em> argument are ignored; they are for API compatibility to <a href="IO.html"><code>IO</code></a>.</p>

                              <div class="method-source-code" id="set_encoding-source">
            <pre>static VALUE
strio_set_encoding(int argc, VALUE *argv, VALUE self)
{
    rb_encoding* enc;
    struct StringIO *ptr = StringIO(self);
    VALUE ext_enc, int_enc, opt;

    argc = rb_scan_args(argc, argv, &quot;11:&quot;, &amp;ext_enc, &amp;int_enc, &amp;opt);

    if (NIL_P(ext_enc)) {
        enc = rb_default_external_encoding();
    }
    else {
        enc = rb_find_encoding(ext_enc);
        if (!enc) {
            rb_io_enc_t convconfig;
            int oflags, fmode;
            VALUE vmode = rb_str_append(rb_str_new_cstr(&quot;r:&quot;), ext_enc);
            rb_io_extract_modeenc(&amp;vmode, 0, Qnil, &amp;oflags, &amp;fmode, &amp;convconfig);
            enc = convconfig.enc2;
        }
    }
    ptr-&gt;enc = enc;
    if (WRITABLE(self)) {
        rb_enc_associate(ptr-&gt;string, enc);
    }

    return self;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-set_encoding_by_bom" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">set_encoding_by_bom</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="set_encoding_by_bom-source">
            <pre>static VALUE
strio_set_encoding_by_bom(VALUE self)
{
    struct StringIO *ptr = StringIO(self);

    if (!set_encoding_by_bom(ptr)) return Qnil;
    return rb_enc_from_encoding(ptr-&gt;enc);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-size" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          size   &rarr; integer
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the size of the buffer string.</p>

                              <div class="method-source-code" id="size-source">
            <pre>static VALUE
strio_size(VALUE self)
{
    VALUE string = StringIO(self)-&gt;string;
    if (NIL_P(string)) {
        rb_raise(rb_eIOError, &quot;not opened&quot;);
    }
    return ULONG2NUM(RSTRING_LEN(string));
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="StringIO.html#method-i-length">length</a>
                            </div>

                          </div>

                  <div id="method-i-string" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          string &rarr; string
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns underlying string:</p>

<pre class="ruby"><span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">open</span>(<span class="ruby-string">&#39;foo&#39;</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">strio</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">strio</span>.<span class="ruby-identifier">string</span>
  <span class="ruby-identifier">strio</span>.<span class="ruby-identifier">string</span> = <span class="ruby-string">&#39;bar&#39;</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">strio</span>.<span class="ruby-identifier">string</span>
<span class="ruby-keyword">end</span>
</pre>

<p>Output:</p>

<pre class="ruby"><span class="ruby-string">&quot;foo&quot;</span>
<span class="ruby-string">&quot;bar&quot;</span>
</pre>

<p>Related: <a href="StringIO.html#method-i-string-3D"><code>StringIO#string=</code></a> (assigns the underlying string).</p>

                              <div class="method-source-code" id="string-source">
            <pre>static VALUE
strio_get_string(VALUE self)
{
    return StringIO(self)-&gt;string;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-string-3D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          string = other_string &rarr; other_string
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Assigns the underlying string as <code>other_string</code>, and sets position to zero; returns <code>other_string</code>:</p>

<pre class="ruby"><span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">open</span>(<span class="ruby-string">&#39;foo&#39;</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">strio</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">strio</span>.<span class="ruby-identifier">string</span>
  <span class="ruby-identifier">strio</span>.<span class="ruby-identifier">string</span> = <span class="ruby-string">&#39;bar&#39;</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">strio</span>.<span class="ruby-identifier">string</span>
<span class="ruby-keyword">end</span>
</pre>

<p>Output:</p>

<pre class="ruby"><span class="ruby-string">&quot;foo&quot;</span>
<span class="ruby-string">&quot;bar&quot;</span>
</pre>

<p>Related: <a href="StringIO.html#method-i-string"><code>StringIO#string</code></a> (returns the underlying string).</p>

                              <div class="method-source-code" id="string-3D-source">
            <pre>static VALUE
strio_set_string(VALUE self, VALUE string)
{
    struct StringIO *ptr = StringIO(self);

    rb_io_taint_check(self);
    ptr-&gt;flags &amp;= ~FMODE_READWRITE;
    StringValue(string);
    ptr-&gt;flags = OBJ_FROZEN(string) ? FMODE_READABLE : FMODE_READWRITE;
    ptr-&gt;pos = 0;
    ptr-&gt;lineno = 0;
    RB_OBJ_WRITE(self, &amp;ptr-&gt;string, string);
    return string;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-sync" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          sync &rarr; true
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code>; implemented only for compatibility with other stream classes.</p>

                              <div class="method-source-code" id="sync-source">
            <pre>static VALUE
strio_get_sync(VALUE self)
{
    StringIO(self);
    return Qtrue;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-sync-3D" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">sync=</span><span
                                class="method-args">(p1)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the argument unchanged.  Just for compatibility to <a href="IO.html"><code>IO</code></a>.</p>

                              <div class="method-source-code" id="sync-3D-source">
            <pre>static VALUE
strio_first(VALUE self, VALUE arg)
{
    StringIO(self);
    return arg;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-tell" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          pos &rarr; stream_position
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the current position (in bytes); see <a href="IO.html#class-IO-label-Position">Position</a>.</p>

                              <div class="method-source-code" id="tell-source">
            <pre>static VALUE
strio_get_pos(VALUE self)
{
    return LONG2NUM(StringIO(self)-&gt;pos);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-truncate" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          truncate(integer)    &rarr; 0
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Truncates the buffer string to at most <em>integer</em> bytes. The stream must be opened for writing.</p>

                              <div class="method-source-code" id="truncate-source">
            <pre>static VALUE
strio_truncate(VALUE self, VALUE len)
{
    VALUE string = writable(self)-&gt;string;
    long l = NUM2LONG(len);
    long plen = RSTRING_LEN(string);
    if (l &lt; 0) {
        error_inval(&quot;negative length&quot;);
    }
    rb_str_resize(string, l);
    if (plen &lt; l) {
        MEMZERO(RSTRING_PTR(string) + plen, char, l - plen);
    }
    return INT2FIX(0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-tty-3F" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">tty?</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>false</code>.  Just for compatibility to <a href="IO.html"><code>IO</code></a>.</p>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="StringIO.html#method-i-isatty">isatty</a>
                            </div>
                          </div>

                  <div id="method-i-ungetbyte" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          ungetbyte(byte) &rarr; nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Pushes back (“unshifts”) an 8-bit byte onto the stream; see <a href="IO.html#class-IO-label-Byte+IO">Byte IO</a>.</p>

                              <div class="method-source-code" id="ungetbyte-source">
            <pre>static VALUE
strio_ungetbyte(VALUE self, VALUE c)
{
    struct StringIO *ptr = readable(self);

    check_modifiable(ptr);
    if (NIL_P(c)) return Qnil;
    if (RB_INTEGER_TYPE_P(c)) {
        /* rb_int_and() not visible from exts */
        VALUE v = rb_funcall(c, &#39;&amp;&#39;, 1, INT2FIX(0xff));
        const char cc = NUM2INT(v) &amp; 0xFF;
        strio_unget_bytes(ptr, &amp;cc, 1);
    }
    else {
        long cl;
        SafeStringValue(c);
        cl = RSTRING_LEN(c);
        if (cl &gt; 0) {
            strio_unget_bytes(ptr, RSTRING_PTR(c), cl);
            RB_GC_GUARD(c);
        }
    }
    return Qnil;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-ungetc" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          ungetc(character) &rarr; nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Pushes back (“unshifts”) a character or integer onto the stream; see <a href="IO.html#class-IO-label-Character+IO">Character IO</a>.</p>

                              <div class="method-source-code" id="ungetc-source">
            <pre>static VALUE
strio_ungetc(VALUE self, VALUE c)
{
    struct StringIO *ptr = readable(self);
    rb_encoding *enc, *enc2;

    check_modifiable(ptr);
    if (NIL_P(c)) return Qnil;
    if (RB_INTEGER_TYPE_P(c)) {
        int len, cc = NUM2INT(c);
        char buf[16];

        enc = rb_enc_get(ptr-&gt;string);
        len = rb_enc_codelen(cc, enc);
        if (len &lt;= 0) rb_enc_uint_chr(cc, enc);
        rb_enc_mbcput(cc, buf, enc);
        return strio_unget_bytes(ptr, buf, len);
    }
    else {
        SafeStringValue(c);
        enc = rb_enc_get(ptr-&gt;string);
        enc2 = rb_enc_get(c);
        if (enc != enc2 &amp;&amp; enc != rb_ascii8bit_encoding()) {
            c = rb_str_conv_enc(c, enc2, enc);
        }
        strio_unget_bytes(ptr, RSTRING_PTR(c), RSTRING_LEN(c));
        RB_GC_GUARD(c);
        return Qnil;
    }
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-write" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          write(string, ...) &rarr; integer
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          syswrite(string)   &rarr; integer
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Appends the given string to the underlying buffer string. The stream must be opened for writing.  If the argument is not a string, it will be converted to a string using <code>to_s</code>. Returns the number of bytes written.  See IO#write.</p>

                              <div class="method-source-code" id="write-source">
            <pre>static VALUE
strio_write_m(int argc, VALUE *argv, VALUE self)
{
    long len = 0;
    while (argc-- &gt; 0) {
        /* StringIO can&#39;t exceed long limit */
        len += strio_write(self, *argv++);
    }
    return LONG2NUM(len);
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is a service of <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>, purveyors of fine <a href='https://jamesbritt.bandcamp.com/'>dance noise</a></p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

